package com.elm.app;

import com.elm.entity.Admin;
import com.elm.view.AdminView;
import com.elm.view.BusinessView;
import com.elm.view.impl.AdminViewImpl;
import com.elm.view.impl.BusinessViewImpl;
import com.elm.util.ConsoleUtil;

public class ElmAdminEntry {
    public static void main(String[] args) {
        run();
    }

    public static void run() {
        AdminView adminView = new AdminViewImpl();
        BusinessView businessView = new BusinessViewImpl();

        ConsoleUtil.printDivider("饿了么后台管理系统");

        Admin admin = adminView.login();

        if (admin != null) {
            ConsoleUtil.printSuccess("登录成功！欢迎管理员：" + admin.getAdminName());
            int menu = 0;
            while (menu != 5) {
                ConsoleUtil.printMenu(
                        "========= 后台管理菜单 =========",
                        "所有商家列表",
                        "搜索商家",
                        "新建商家",
                        "删除商家",
                        "退出系统"
                );
                menu = ConsoleUtil.readInt();

                switch (menu) {
                    case 1:
                        businessView.listAllBusinesses();
                        break;
                    case 2:
                        businessView.listBusinessesBySearch();
                        break;
                    case 3:
                        businessView.saveBusiness();
                        break;
                    case 4:
                        businessView.removeBusiness();
                        break;
                    case 5:
                        ConsoleUtil.printDivider("欢迎下次使用饿了么后台管理系统");
                        break;
                    default:
                        ConsoleUtil.printError("没有这个选项！");
                        break;
                }
            }
        } else {
            ConsoleUtil.printError("管理员名称或密码错误！");
        }
    }
}
